using RecurUnroll

import Documenter
Documenter.makedocs(
    modules = [RecurUnroll],
    format = :html,
    sitename = "RecurUnroll.jl",
    root = joinpath(dirname(dirname(@__FILE__)), "docs"),
    pages = Any["Home" => "index.md"],
    strict = true,
    linkcheck = true,
    checkdocs = :exports,
    authors = "Brandon Taylor"
)

using Base.Test
@test_throws ArgumentError reduce(+, Unroll(()))

import Base.setindex
x = Unroll((1, 2, 3))
empty = Unroll(())
switch = Unroll((true, true, false))
new = Unroll((4, 5))

@test mapfoldr(identity, +, x) == 6
@test mapfoldr(identity, +, 0, x) == 6
@test mapreduce(identity, +, 0, x) == 6

@test getindex(x, empty) == empty
@test getindex(empty, switch) == empty

@test x[empty] == empty
@test empty[switch] == empty

@test setindex(empty, 0, switch) == empty
@test setindex(x, 0, empty) == x

@test setindex(empty, empty, switch) == empty
@test setindex(empty, new, empty) == empty
@test setindex(empty, new, switch) == empty
@test setindex(x, empty, empty) == x
@test setindex(x, empty, switch) == x
@test setindex(x, new, empty) == x

@test setindex(empty, empty, empty, 0) == empty
@test setindex(empty, empty, switch, 0) == empty
@test setindex(empty, new, empty, 0) == empty
@test setindex(empty, new, switch, 0) == empty
@test setindex(x, empty, empty, 0) == x
@test setindex(x, new, empty, 0) == x

@test map(*, empty, x) == empty
@test map(*, x, empty) == empty

@test map(*, empty, empty, x) == empty
@test map(*, empty, x, empty) == empty
@test map(*, empty, x, x) == empty
@test map(*, x, empty, empty) == empty
@test map(*, x, empty, x) == empty
@test map(*, x, x, empty) == empty
